﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockFinder.Model;

namespace StockFinder.YahooFinance
{
    public class Utils
    {
        public static string FormattedForExchange(Symbol symbol)
        {
            var formattedSymbolName = symbol.Name;

            switch (symbol.Exchange)
            {
                case Model.Enumerations.Exchange.None:
                case Model.Enumerations.Exchange.NASDAQ:
                case Model.Enumerations.Exchange.NYSE:
                case Model.Enumerations.Exchange.AMEX:
                    break;
                case Model.Enumerations.Exchange.LONDON:
                    if (!symbol.Name.EndsWith(".L"))
                    {
                        formattedSymbolName = string.Format("{0}.L", symbol.Name);
                    }
                    break;
                default:
                    break;
            }

            return formattedSymbolName;
        }

        public static string Formatted(Symbol symbol)
        {
            //1 format for exchange
            var symbolName = FormattedForExchange(symbol);

            //2 remove website specific characters for yahoo finance
            symbolName = symbolName.Replace("^", "-P");
            symbolName = symbolName.Replace("/", "-");

            return symbolName;
        }
    }
}
